<template>
</template>

<script>
  import {appid, inviter_uri} from "@/config/config";

  export default {
    name: "Auth",
    data() {
      return {}
    },
    created() {
      this.get_wxinfo();
    },
    methods: {
      //获取微信授权
      get_wxinfo() {
        let {path} = this.$route.query;
        path = path || '/login';
        path = decodeURIComponent(path);
        // 当用户已经登录并且授权后跳转到登录页面时退出页面
        if (this.$store.state.userInfo.uid && /^\/login\/?/.test(path)) return this.$router.go(-1);
        let redirect_uri = encodeURIComponent(inviter_uri + path);
        let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
        // console.log('url::', url);
        // return console.log('redirect_uri::', redirect_uri);
        // alert(url);
        location.replace(url);
      },

    },

  }
</script>

<style>
</style>
